function CheckNumber(str){
	var pattern =/^[0-9]+$/;
	return pattern.test(str);
}
function CheckName(str) { 
	var pattern =/^[A-Za-z0-9]+$/;
	return pattern.test(str);
}
function CheckStr2(str) { 
	var pattern =/^[A-Za-z0-9_\.\/-]+$/;
	return pattern.test(str);
}
function CheckDevname(str) { 
	var pattern =/^[A-Za-z0-9]+$/;
	return pattern.test(str);
}
function checkIP(sIPAddress) {
	var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/; 
	var reg = sIPAddress.match(exp);
	if (reg == null) {
		return false;
	}
	return true;
}
function checkNetIP(sIPAddress) {
	if (sIPAddress == "0.0.0.0")
		return true;
	var exp=/^([1-9][0-9]{0,1}|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9][0-9]{0,1}|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9][0-9]{0,1}|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9][0-9]{0,1}|1\d\d|2[0-4]\d|25[0-5])$/;
	var reg = sIPAddress.match(exp);
	if (reg == null) {
		return false;
	}
	return true;
}
function checkMask(sIPAddress) {
	if (sIPAddress == "0.0.0.0")
		return true;
	var exp=/^([1-9][0-9]{0,1}|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9][0-9]{0,1}|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9][0-9]{0,1}|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9][0-9]{0,1}|1\d\d|2[0-4]\d|25[0-5])$/;
	var reg = sIPAddress.match(exp);
	if (reg == null) {
		return false;
	}
	return true;
}
function IsNumeric(str) {
   isNum=/^[0-9]{0,128}$/;
   return(isNum.test(str));
}
function CheckPort(str) {
	if ( (IsNumeric(str) != true) || (str > 65535) || (str < 0 ))
		return false;
	return true;
}
function CheckProtoCode(str) {
	if (IsNumeric(str)!=true || (str>255 || str<0))
		return false;
	return true;
}
function add_branch() {
	var i,j,is_selected;
	if (document.form1.sel_branch.options.length > 0) {
		for (i=0; i<document.form1.sel_branch.options.length; i++) {
			if (document.form1.sel_branch.options[i].selected == true) {
				var opt = new Option(document.form1.sel_branch.options[i].text, document.form1.sel_branch.options[i].value);
				document.form1.selected_branch.options[document.form1.selected_branch.length] = opt;
				document.form1.sel_branch.options[i] = null;				
				break;
			}
		}
	}
}
function del_branch() {
	var k;
	if (document.form1.selected_branch.options.length > 0)
		for (k=0; k<document.form1.selected_branch.options.length; k++) {
			if (document.form1.selected_branch.options[k].selected == true) {
				var opt = new Option(document.form1.selected_branch.options[k].text, document.form1.selected_branch.options[k].value);
				document.form1.sel_branch.options[document.form1.sel_branch.length] = opt;
				document.form1.selected_branch.options[k] = null;
				break;
			}
		}
}
// select ip:
function sip(pro) {
	if(pro == '0') {
		document.getElementById('OBJ1').style.display = "block";
		document.getElementById('SIP1').style.display = "block";
		document.getElementById('NIP1').style.display = "none";
		document.getElementById('EIP1').style.display = "block";
		document.getElementById('MASK1').style.display = "none";
		document.getElementById('IPadd1').style.display = "none";
	}
	if(pro == '2') {
		document.getElementById('OBJ1').style.display = "block";
		document.getElementById('SIP1').style.display = "none";
		document.getElementById('NIP1').style.display = "none";
		document.getElementById('EIP1').style.display = "none";
		document.getElementById('MASK1').style.display = "none";
		document.getElementById('IPadd1').style.display = "block";
	}
	if(pro == '1') {
		document.getElementById('OBJ1').style.display = "block";
		document.getElementById('SIP1').style.display = "none";
		document.getElementById('NIP1').style.display = "block";
		document.getElementById('EIP1').style.display = "none";
		document.getElementById('MASK1').style.display = "block";
		document.getElementById('IPadd1').style.display = "none";
	}
}
// select port:
function sport(pro) {
	if(pro == "1")	{
		document.getElementById('SRCSPORT1').style.display = "none";
		document.getElementById('SRCEPORT1').style.display = "none";
		document.getElementById('DSTSPORT1').style.display = "none";
		document.getElementById('DSTEPORT1').style.display = "none";
		document.getElementById('PROTOCOL1').style.display = "none";
		document.getElementById('ICMPTYPE1').style.display = "block";
	}
	if (pro == "OTHER") {
		document.getElementById('SRCSPORT1').style.display = "none";
		document.getElementById('SRCEPORT1').style.display = "none";
		document.getElementById('DSTSPORT1').style.display = "none";
		document.getElementById('DSTEPORT1').style.display = "none";
		document.getElementById('ICMPTYPE1').style.display = "none";
		document.getElementById('PROTOCOL1').style.display = "block";
	}
	if (pro == "6") {
		document.getElementById('SRCSPORT1').style.display = "block";
		document.getElementById('SRCEPORT1').style.display = "block";
		document.getElementById('DSTSPORT1').style.display = "block";
		document.getElementById('DSTEPORT1').style.display = "block";
		document.getElementById('PROTOCOL1').style.display = "none";
		document.getElementById('ICMPTYPE1').style.display = "none";
	}
	if (pro == "17") {
		document.getElementById('SRCSPORT1').style.display = "block";
		document.getElementById('SRCEPORT1').style.display = "block";
		document.getElementById('DSTSPORT1').style.display = "block";
		document.getElementById('DSTEPORT1').style.display = "block";
		document.getElementById('PROTOCOL1').style.display = "none";
		document.getElementById('ICMPTYPE1').style.display = "none";
	}
}
// select month:
function seldaynum(pro,yearflag) {
	if(pro == '01' || pro == '03' || pro == '05' || pro == '07' || pro == '08' || pro == '10' || pro == '12') {
		document.getElementById('day').style.display = "block";
		document.getElementById('time').style.display = "block";
		document.getElementById('sel_year').style.display = "block";
		document.getElementById('sel_mon').style.display = "block";
		document.getElementById('sel_day31').style.display = "block";
		document.getElementById('sel_day30').style.display = "none";
		document.getElementById('sel_day28').style.display = "none";
		document.getElementById('sel_day29').style.display = "none";
		document.getElementById('sel_hour').style.display = "block";
		document.getElementById('sel_min').style.display = "block";
		document.getElementById('sel_sec').style.display = "block";
		document.getElementById('conf_time_reflash').style.display = "block";
	}
	if(pro == '04' || pro == '06' || pro == '09' || pro == '11' ) {
		document.getElementById('day').style.display = "block";
		document.getElementById('time').style.display = "block";
		document.getElementById('sel_year').style.display = "block";
		document.getElementById('sel_mon').style.display = "block";
		document.getElementById('sel_day31').style.display = "none";
		document.getElementById('sel_day30').style.display = "block";
		document.getElementById('sel_day28').style.display = "none";
		document.getElementById('sel_day29').style.display = "none";
		document.getElementById('sel_hour').style.display = "block";
		document.getElementById('sel_min').style.display = "block";
		document.getElementById('sel_sec').style.display = "block";
		document.getElementById('conf_time_reflash').style.display = "block";
	}
	if(pro == '02') {
		if( (yearflag % 4 == 0) && (yearflag % 100 != 0) || (yearflag % 400 == 0) )
		{
			document.getElementById('day').style.display = "block";
			document.getElementById('time').style.display = "block";
			document.getElementById('sel_year').style.display = "block";
			document.getElementById('sel_mon').style.display = "block";
			document.getElementById('sel_day31').style.display = "none";
			document.getElementById('sel_day30').style.display = "none";
			document.getElementById('sel_day28').style.display = "none";
			document.getElementById('sel_day29').style.display = "block";
			document.getElementById('sel_hour').style.display = "block";
			document.getElementById('sel_min').style.display = "block";
			document.getElementById('sel_sec').style.display = "block";
			document.getElementById('conf_time_reflash').style.display = "block";
		}
		else
		{
			document.getElementById('day').style.display = "block";
			document.getElementById('time').style.display = "block";
			document.getElementById('sel_year').style.display = "block";
			document.getElementById('sel_mon').style.display = "block";
			document.getElementById('sel_day31').style.display = "none";
			document.getElementById('sel_day30').style.display = "none";
			document.getElementById('sel_day28').style.display = "block";
			document.getElementById('sel_day29').style.display = "none";
			document.getElementById('sel_hour').style.display = "block";
			document.getElementById('sel_min').style.display = "block";
			document.getElementById('sel_sec').style.display = "block";
			document.getElementById('conf_time_reflash').style.display = "block";
		}
	}
}
